<?php

namespace Xin\Coze\Providers;

class AudioProvider extends AbstractProvider
{
	/**
	 * 查看音色列表
	 * @param array{
	 *     filter_system_voice: bool,
	 *     page_num:int,
	 *     page_size:int,
	 * } $query
	 * @param array $options
	 * @return array
	 */
	public function voices(array $query = [], array $options = [])
	{
		return $this->coze->httpGet('/v1/audio/voices', $query, $options);
	}

	/**
	 * 创建房间
	 * @param string $botId
	 * @param array{
	 *     conversation_id?:string,
	 *     voice_id?:string,
	 *     config?:array{
	 *         audio_config?:array{
	 *             codec:string
	 *         },
	 *         video_config?:array{
	 *             codec:string,
	 *             stream_video_type:string,
	 *         }
	 *     },
	 *     uid?:string,
	 *     workflow_id?:string,
	 * } $data
	 * @param array $options
	 * @return array
	 * @see https://doc.ark.cn-beijing.volces.com/zh-cn/docs/api/audio/createRoom
	 */
	public function createRoom(string $botId, array $data = [], array $options = [])
	{
		$data = array_merge($data, [
			'bot_id' => $botId,
		]);
		return $this->coze->httpPost('/v1/audio/rooms', $data, $options);
	}

	/**
	 * 语音合成
	 * @param string $text
	 * @param array{
	 *     voice_id?:string,
	 *     response_format?:string,
	 *     speed?:float,
	 *     sample_rate?:string,
	 * } $data
	 * @param array $options
	 * @return Response
	 * @see https://doc.ark.cn-beijing.volces.com/zh-cn/docs/api/audio/speech
	 */
	public function speech(string $text, array $data = [], array $options = [])
	{
		$data = array_merge([
			'voice_id' => '7426720361733013513',
			'response_format' => 'wav',
		], $data, [
			'input' => $text,
		]);

		return $this->coze->httpPost('/v1/audio/speech', $data, $options);
	}

	/**
	 * 语音识别
	 * @param string $filepath
	 * @param array $options
	 * @return Response
	 * @see https://doc.ark.cn-beijing.volces.com/zh-cn/docs/api/audio/transcriptions
	 */
	public function transcription(string $filepath, array $options = [])
	{
		return $this->coze->client()->upload('/v1/audio/transcriptions', [
			'file' => $filepath,
		], [], [], $options);
	}

}
